<template>
	<view class="u-page">
		<view class="header">
		</view>
		<view class="content">

			<view class="projectList" v-if="lists!=''">
				<view class="label">投资合同</view>
				<block v-for="(item, index) in lists" :key="index">
					<view class="lists">
						<view class="filename">
							<image src="../../../static/icon/file.png" mode=""></image>
						</view>
						<view class="list_contnet">
							<view class="projecttitle">{{item.filename}}</view>
						</view>
						<view class="chakan" @click="downLoadFile(item.filepath)">
							<view>查看</view>
						</view>
						<image src="../../../static/icon/downlow.png" style="width: 16px;height: 16px;" mode=""></image>
					</view>
				</block>
			</view>
			
			<view class="projectList" v-else>
				<view class="label">暂无信息</view>
				
			</view>
			
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				pid: '',
				lists: [],
			}
		},
		onLoad(data) {
			console.log(data)
			this.pid = data.id
			this.filesList();

		},
		methods: {
			goback() {
				uni.navigateBack({
					delta: 1
				})
			},
			async filesList() {
				console.log('1111', this.type)
				const files = await this.GQL({
					"operationName": "allSlProjectContractFiles",
					"query": "query allSlProjectContractFiles($filter: SlProjectContractFileFilter) { allSlProjectContractFiles(filter:$filter) { nodes { id pid uid filename createtime filepath } } }",
					"variables": {
						"filter": {
							"pid": {
								"equalTo": this.pid
							}
						}
					}
				})
				if (files.data.allSlProjectContractFiles.nodes != '') {

					this.lists = files.data.allSlProjectContractFiles.nodes
				}
			},
			downLoadFile(path) {
				uni.showLoading({
					title: '下载中...',
				})
				console.log('1---', path)
				uni.downloadFile({
					url: path,
					success(res) {
						console.log('33333', res);
						var filePath = res.tempFilePath;
						uni.openDocument({
							filePath: filePath,
							success: function(res) {
								uni.hideLoading()
								console.log('打开文档成功');
							},
							fail: (e) => {
								console.log(e);
							},
						});
						//保存到本地
						//  uni.saveFile({
						// tempFilePath: res.tempFilePath,
						// success: function (res) {
						// 	console.log('res',res)
						//   const savedFilePath = res.savedFilePath;
						//   // 打开文件
						//   uni.openDocument({
						// 	filePath: savedFilePath,
						// 	success: function (res) {
						// 	  uni.hideLoading()
						// 	},
						//   });
						// },
						// fail: function (err) {
						// 	uni.hideLoading();
						// 	uni.showLoading({
						// 		title: '保存失败',
						// 	})
						// }
						//  });
					},
					fail(res) {
						console.log('2222', res)
						uni.hideLoading();
						uni.showLoading({
							title: '下载失败',
						})
					}
				})
			}


		}
	}
</script>

<style lang="scss">
	.u-page {
		background-color: #FBFCFE;
	}

	.header {
		width: 100%;
		height: 200px;
		/* color: #FFFFFF; */
		background: linear-gradient(#C7171E, #f0f2f5);
		/* 标准的语法 */

	}

	.content {
		position: relative;
		top: -200px;

		margin: 15px;

		.projectList {
			background-color: #FFFFFF;
			border-radius: 5px;
			min-height: 500px;
			padding: 22px 16px;

			.label {
				font-size: 16px;
				font-family: PingFangSC-Medium, PingFang SC;
				font-weight: 600;
				color: #161E3E;
				line-height: 16px;
				margin-bottom: 28px;
			}

			.lists {
				margin-top: 8px;
				display: flex;
				border-bottom: 1px solid #D7D7D7;
				height: 30px;
				justify-content: space-between;
			}


			.list_contnet {
				flex: 1;
				width: 200px;
				margin-left: 10px;
			}

			.filename {
				font-size: 12px;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #161E3E;
				line-height: 16px;
			}

			.chakan {
				font-size: 12px;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #007AFF;
				line-height: 16px;
				margin-right: 10px;
			}

			image {
				width: 22px;
				height: 22px;
			}

		}
	}
</style>
